package com.datamation.swadeshi.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.datamation.swadeshi.R;
import com.datamation.swadeshi.control.ReferenceNum;
import com.datamation.swadeshi.control.data.DamagePrintDS;
import com.datamation.swadeshi.control.data.LoadingPrintDS;
import com.datamation.swadeshi.control.data.SalOrdPrintDS;
import com.datamation.swadeshi.model.DamagePrintPre;
import com.datamation.swadeshi.model.LoadingPrintPre;
import com.datamation.swadeshi.model.SalOrdPrintPre;

public class PrintDamageItemAdapter extends ArrayAdapter<DamagePrintPre> {
	Context context;
	ArrayList<DamagePrintPre> list;
	private DamagePrintDS dsDamagePrintDS;
	int totcases=0;
	int totpieces=0;
	int StrPrintCaseQtyVal=0;
	ReferenceNum referenceNum ;
	public PrintDamageItemAdapter(Context context, ArrayList<DamagePrintPre> list) {

		super(context, R.layout.row_printloadingitems_listview, list);
		this.context = context;
		this.list = list;
		dsDamagePrintDS = new DamagePrintDS(context);
		referenceNum =new  ReferenceNum(context);
	}

	@Override
	public View getView(int position, final View convertView,
			final ViewGroup parent) {

		LayoutInflater inflater = null;
		View row = null;
		ArrayList<DamagePrintPre> damageprintList;
		damageprintList = dsDamagePrintDS.getAllLoadingListPreview(referenceNum.getCurrentRefNo(context.getResources().getString(R.string.NumVal)));
		int ll = damageprintList.size();

		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		row = inflater.inflate(R.layout.row_printloadingitems_listview, parent, false);

		LinearLayout layout = (LinearLayout) row.findViewById(R.id.linearLayout);
		TextView itemname = (TextView) row.findViewById(R.id.printitemname);
		TextView casepieceqty = (TextView) row.findViewById(R.id.printcasepieceaqy);
		TextView printindex = (TextView) row.findViewById(R.id.printindex);
		TextView amount = (TextView) row.findViewById(R.id.printamount);
		String caseqty =  list.get(position).getDAMG_PRINT_CASE_QTY();
		String pieceqty =  list.get(position).getDAMG_PRINT_PIECE_QTY();
		String cpqty = caseqty+"/"+pieceqty;
		
		itemname.setText(list.get(position).getDAMG_PRINT_ITEMNAME());
		casepieceqty.setText(cpqty);
		amount.setText(list.get(position).getDAMG_PRINT_AMT());
		position = position +1;
		String pos = Integer.toString(position);
		printindex.setText(pos+".");
		


		
		return row;
	}
}
